package com.example.mapper;

import com.example.pojo.entity.Order;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface OrderMapper {
    @Insert("insert into `order`(order_num,goods_name,number,price,create_time,pay_num,pay_time,order_state,user_id,type) " +
            "values(#{orderNum},#{goodsName},#{number},#{price},#{createTime},#{payNum},#{payTime},#{orderState},#{userId},#{type})")
    void insert(Order order);

    @Update("update `order` set order_num=#{orderNum},goods_name=#{goodsName},number=#{number},price=#{price},create_time=#{createTime}," +
            "pay_num=#{payNum},pay_time=#{payTime},order_state=#{orderState},user_id=#{userId},type=#{type} where id=#{id}")
    void updateOrder(Order order);

    @Delete("delete from `order` where id=#{id}")
    void removeById(Integer id);

    @Select("select * from `order`")
    List<Order> list();

    @Select("select * from `order `where id=#{id}")
    Order getById(Integer id);

    List<Order> selectByPage(String goodsName, Integer userId);

    @Select("select * from `order` where order_num=#{orderNum}")
    Order getByOrderNum(String orderNum);

    @Select("select * from `order` where user_id=#{userId} and type = #{type}")
    List<Order> selectByUserId(Integer userId,Integer type);
}
